/*引入dgram模块*/
var dgram=require('dgram')
/*创建UDP客户端*/
var client=dgram.createSocket('udp4');
    /*输入进程*/
    process.stdin.resume();
    process.stdin.on('data',function (data) {
            if(data.toString().trim().toLowerCase()==='stop'){
                client.close();
            }
            /*创建buff*/
            var message=Buffer.alloc(data.toString().trim().length,data.toString().trim());
            //发送数据
            client.send(message,0,message.length,8888,'localhost',function (err, bytes) {
            if(err){
                console.log(err);
                return;
            }
            // console.log(client.address()+':'+bytes)
        })
    });
client.on('message',function (msg,rinfo) {
          console.log(msg.toString());
})